TK!2
=v
#1
:n

:s
b
:c
*Root of equation by Bisection method*
#3
:n
y
:s
b
:c
)  used for generating 
:a
y
#4
:n
x
:v
5
:s
i
:c
)  the graph of y=f(x)
:a
x
#5
:n
fun
:v
'weird
:s
i
:c
function name
#6
:n
from
:v
2
:s
i
:c
lower limit of search interval
#7
:n
to
:v
8
:s
i
:c
upper limit of search interval
#8
:n
result
:v
4.831650547683239
:s
o
:c
root
=u
=l
#1
:n
x
:v
.001
.2
.4
.6000000000000001
.8
1
1.2
1.4
1.6
1.8
2
2.2
2.4
2.6
2.8
3
3.2
3.4
3.6
3.8
4
4.2
4.4
4.600000000000001
4.800000000000001
5
5.2
5.4
5.600000000000001
5.800000000000001
6
6.2
6.4
6.600000000000001
6.800000000000001
7
7.2
7.4
7.600000000000001
7.800000000000001
8

5
5
1.987
1.987
3.815
3.815
-.578
E
#2
:n
y
:v
-.00951718902475478
-.8120693619352195
-1.192150943088438
-1.300382123332028
-1.314704671937063
-1.417653057501473
-1.65665652712839
-1.9135492658818
-2.02096650242606
-1.921395942605918
-1.723777241570436
-1.606159173243486
-1.654211436592394
-1.784242222622654
-1.821613257847212
-1.662534439329395
-1.370538065077929
-1.118972936384837
-1.032417191744995
-1.07283545559928
-1.075163255402364
-.8996153537152773
-.5606965727854122
-.2143113202845996
-.01482990129589926
.0264703500195546
.05143601830114239
.2243144364541928
.5804594800576452
.99356280652858
1.2915356655823
1.414498082689675
1.469619162513427
1.632387089527192
1.985079421062129
2.44094219024772
2.82378618852157
3.029819076213975
3.12292482918033
3.27579032858246
3.611006401870015
E
#3
:n
ytr
:v










































0
.0265
0
-1.736
0
-1.077
0
E
=f
#1
:n
weird
:c
y = f(x)
:t
Rule
:a
x
:v
y
#2
:n
bisect
:c
Bisection method
:t
Procedure
:i
fun,a,b
:o
x
#1
:n
weird
:z
y = x*ln(x/5) - sin(5*x)/5
/E
E
#2
:n
bisect
:z
Notation:
" fun  - function name
" a,b  - limits of the search interval
" x    - root of the equation fun(x)=0

Description:
"    The procedure represents a standard bisection method, i.e. reduction of
" the interval containing the root until its relative width is smaller than
" a given parameter (such as 1e-8, see the statement marked "testing...).
" The absence or ambiguity of roots within the search interval is indicated
" by an error condition and message. There is no built-in limit for the
" number of iteration steps.

y:= sgn(apply(fun,a))
y1:= sgn(apply(fun,b))
if y=y1 then error:= no_root_or_even_number_of_roots_in_search_interval
loop: x:= .5*(a + b)
      y:= sgn(apply(fun,x))
      if abs(a-b)/max(abs(a),abs(b)) < 1e-8 return
                                  " (testing the width of interval a,b)
      if y=y1 goto newb
      a:= x
      goto loop
newb: b:= x
      y1:= y
      goto loop
/E
E
=r
#1
:r
y = x*ln(x/5) - sin(5*x)/5      " used for generating the graph of y=f(x)
:s
C
#2
:r
result = bisect(fun,from,to)    " used for finding the root
#4
:r
" Notes ([PgDn] for more):
:s
C
#6
:r
" Bisection method for finding a root of an equation is usually slower than
:s
C
#7
:r
" the Newton-Raphson method used by TK's Iterative Solver, but it is less
:s
C
#8
:r
" sensitive to the quality of the initial guess.
:s
C
#10
:r
" The TK built-in Iterative Solver using the Newton-Raphson procedure fails
:s
C
#11
:r
" to find the root of the above equation even if the guess is as close as
:s
C
#12
:r
" x=5 (look at the plots 'weird' and 'zoomed', with a sequence of tangents
:s
C
#13
:r
" showing the "progress" of the Newton-Raphson procedure, to see why).
:s
C
#15
:r
" The procedure 'bisect', given the search interval between 2 and 8, finds
:s
C
#16
:r
" the root in 28 steps going through  x = 5, 3.5, 4.25, 4.625, 4.8125,
:s
C
#17
:r
" 4.90625, 4.859375, ..., 4.8316505 .
:s
C
=p
#1
:n
weird
:t
Line chart
:d
EGA
:i
"y = x*ln(x/5) - sin(5*x)/5  and iteration trace from x=5"
:s
Yes
:z
Both
:g
No
:l
None
:h
"x"
:v
"y"
:a
-1,8
:x
x
:u
#1
:y
y
:f
1
:p
Lines
:c
"*"
#2
:y
ytr
:f
1
:p
Lines
:c
""
E
#2
:n
weird_zoomed
:t
Line chart
:d
EGA
:i
"y = x*ln(x/5) - sin(5*x)/5  and iteration trace from x=5"
:s
Yes
:z
Both
:g
No
:l
None
:h
"x"
:v
"y"
:a
-1,6
:b
-2,.5
:x
x
:u
#1
:y
y
:f
1
:p
Lines
:c
"*"
#2
:y
ytr
:f
1
:p
Both
:c
""
E
=t
=n
=g
#1
:c
.000001
:i
1
:v
Yes
:l
60
:f
66
:m
0
:w
80
:b
Yes
:a
Yes
:r
Yes
:h
No
:t
1
:n
Yes
:d
LPT1
%Tv,f,0,5,0,1,0
%Or,f,3,1,0,1,0
